package sns.action;

import java.util.Date;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.Mblog;
import sns.dao.MblogDao;
import sns.dao.UserDao;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class PublishAction extends ActionSupport {
	// injection
	UserDao userDao;
	MblogDao mblogDao;
	// pass in
	private String publishContent;
	private Long userId;
	// return
	private Long visitId;

	// parameter
	Mblog mblog;

	@Transactional
	public String execute() {

		mblog = new Mblog();
		mblog.setMblogTxt(publishContent);
		System.out.println("################################content is "
				+ publishContent);
		mblog.setPublisher(userDao.findUserById(userId));
		mblog.setMblogTime(new Date());
		mblogDao.save(mblog);

		visitId = userId;

		return Action.SUCCESS;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Long getReturnId() {
		return visitId;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void setMblogDao(MblogDao mblogDao) {
		this.mblogDao = mblogDao;
	}

	public void setPublishContent(String publishContent) {
		this.publishContent = publishContent;
	}

}
